<template>
  <div class="app-container">
    <el-table v-loading="loading" :data="fuzerenCertTwoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="内部id" align="center" prop="id" />
      <el-table-column label="申办人数" align="center" prop="sum" />
      <el-table-column label="培训班期次" align="center" prop="classTerm" />
      <el-table-column label="报送日期" align="center" prop="sendTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.sendTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            style="width: 40px;"
            @click="handleUpdate(scope.row)"
          >查看</el-button>
          <el-button
            size="mini"
            type="primary"
            style="width: 80px;"
            @click="checkStudentInformation(scope.row)"
          >查看学生信息</el-button>
          <el-button
          v-if="scope.row.approvalProcessSign == 2"
            size="mini"
            type="success"
            style="width: 40px;"
            @click="fuzerenApprovalTwo(scope.row)"
          >审批</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

      <!-- 添加或修改审批办证申请表对话框 -->
      <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form :inline="true" ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="申办人数" prop="sum">
          <el-input v-model="form.sum" placeholder="请输入申办人数" />
        </el-form-item>
        <el-form-item label="培训班期次" prop="classTerm">
          <el-input v-model="form.classTerm" placeholder="请输入培训班期次" />
        </el-form-item>
        <el-form-item label="报送日期" prop="sendTime">
          <el-date-picker clearable
            v-model="form.sendTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择报送日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="培训计划申请" prop="trainplanApplication">
          <file-upload v-model="form.trainplanApplication"/>
        </el-form-item>

        <el-form-item label="考试申请表pdf" prop="examApplicationPdf">
          <file-upload v-model="form.examApplicationPdf"/>
        </el-form-item>
        <el-form-item label="合格证明表pdf" prop="examCertificatePdf">
          <file-upload v-model="form.examCertificatePdf"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="cancel">返 回</el-button>
      </div>
    </el-dialog>


    <!-- 安全管理人员审批一弹窗 -->
    <el-dialog
      title="提示"
      :visible.sync="fuzerenTwoOpen"
      width="30%"
      :center="true">
      <span>审批是否通过办证申请表</span>
      <span slot="footer" class="dialog-footer">
        <el-button type="success" @click="fuzerenTwoApproval(0)">通 过</el-button>
        <el-button type="danger" @click="fuzerenTwoApproval(-1)">不通过</el-button>
        <el-button @click="fuzerenTwoOpen = false">返 回</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { listFuzerenCertTwo, getFuzerenCertTwo, delFuzerenCertTwo, addFuzerenCertTwo, updateFuzerenCertTwo, fuzerenTwoApprovalSubmit } from "@/api/certificate/fuzerenCertTwo";

export default {
  name: "FuzerenCertTwo",
  data() {
    return {
      // 点击审批数据
      CertCertificate: {},
      // 安全管理人员审批一弹窗
      fuzerenTwoOpen: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 办证申请表审批二级表格数据
      fuzerenCertTwoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  watch: {
   $route(to, from) {
       window.location.reload(); //监测到路由发生跳转时刷新一次页面
   },
},
  created() {
    this.getList();
  },
  methods: {
     // 查询学生信息
     checkStudentInformation(row) {
      const ids = row.id;
        window.location.href = "../cert/certQualified?certApplicationId=" + ids;
    },
    // 审批是否通过
    fuzerenTwoApproval(status) {
      this.CertCertificate.isPass = status;
      fuzerenTwoApprovalSubmit(this.CertCertificate).then(response => {
        this.$modal.msgSuccess("审批成功");
        this.fuzerenTwoOpen = false;
        this.getList();
      })
    },
    // 打开特作审批一弹窗
    fuzerenApprovalTwo(row) {
      this.fuzerenTwoOpen = true;
      this.CertCertificate = row;
    },
    /** 查询办证申请表审批二级列表 */
    getList() {
      this.loading = true;
      listFuzerenCertTwo(this.queryParams).then(response => {
        this.fuzerenCertTwoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        sum: null,
        sendTime: null,
        approvalProcessSign: null,
        xzspjsprId: null,
        xzspjfzrId: null,
        gaizhang2Id: null,
        gaizhang2Picture: null,
        yingjifzrId: null,
        yingjizrId: null,
        gaizhang3Id: null,
        gaizhang3Picture: null,
        isDeleted: null,
        createId: null,
        createTime: null,
        updateId: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加办证申请表审批二级";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getFuzerenCertTwo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改办证申请表审批二级";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateFuzerenCertTwo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFuzerenCertTwo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除办证申请表审批二级编号为"' + ids + '"的数据项？').then(function() {
        return delFuzerenCertTwo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('certificate/fuzerenCertTwo/export', {
        ...this.queryParams
      }, `fuzerenCertTwo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
